package b3.util
{
	import b3.config.BuildingConfig;
	import b3.config.Config;
	import b3.model.BuildingModel;
	import b3.scene.home.grid.*;
	
	import flash.utils.getDefinitionByName;
	
	public class B3Factory
	{
		public static var instance:B3Factory;
		
		private var path:String = "";
		
		public function B3Factory()
		{
			
		}
		public function getBuildingGridFactory():B3Factory
		{
			getInstance().path = "";
			return instance;
		}
		
		public function getInstance():B3Factory
		{
			if (!instance)
				instance = new B3Factory();
			instance.path = "";
			return instance;
		}
		
		public function getClassByName(name:String):Class
		{
			return getDefinitionByName(path + name) as Class;
		}
		
		public static function createBuildingGrid(buildingModel:BuildingModel):BuildingGrid
		{
			//普通建筑
			var buildingGrid:BuildingGrid;
			//荣誉堂
			var buildingConfig:BuildingConfig = Config.buildingConfigs[buildingModel.buildingIndex];
			var objClassName:String = buildingConfig.className == "" ? "BuildingGrid" : buildingConfig.className;
			var ObjClass:Class = getDefinitionByName("b3.scene.home.grid." + objClassName) as Class;
			return new ObjClass(buildingModel);
		}
	}
}